package tue.cse.advanceddatabases.project;


import java.util.List;
import java.util.logging.Logger;

import org.dom4j.Element;

import tue.cse.advanceddatabases.project.xml.album.Album;
import tue.cse.advanceddatabases.project.xml.album.AlbumsParser;
import tue.cse.advanceddatabases.project.xml.artist.Artist;
import tue.cse.advanceddatabases.project.xml.artist.ArtistsParser;



public class MusicProfileEngineBean extends MusicEngineBean {
	
	private Logger logger = Logger.getLogger(MusicProfileEngineBean.class.getName());

	/** get Top rated Album List **/
	public List<Album> getTopRatedAlbums(){
	
		String result = executeQueryXQL("topRatedAlbums.xql",null);
		
		if (result != null){
			Element albumsElement = stringToXml(result);
			if (albumsElement!=null){
				logger.info("Albums are contained in" + albumsElement);
				return AlbumsParser.parse(albumsElement);
			}			
		}
		
		return null;
	}
	
	/** get Top rated Album List **/
	public List<Album> getMostCommentedAlbums(){
	
		String result = executeQueryXQL("mostCommentedAlbums.xql",null);
		
		if (result != null){
			Element albumsElement = stringToXml(result);
			if (albumsElement!=null){
				logger.info("Albums are contained in" + albumsElement);
				return AlbumsParser.parse(albumsElement);
			}			
		}
		
		return null;
	}
	
	/** get top rated artists **/
	public List<Artist> getTopRatedArtists(){
		String result = executeQueryXQL("topRatedArtists.xql",null);
		
		if (result != null){
			Element artistsElement = stringToXml(result);
			if (artistsElement!=null){
				logger.info("Artists are contained in" + artistsElement);
				return ArtistsParser.parse(artistsElement);
			}			
		}
		
		return null;		
	}


}